package com.hy.mydesktop.client.mvc.core.builder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.hy.mydesktop.client.component.mvc.event.EventStructureMetaModel;
import com.hy.mydesktop.client.component.type.ComponentControllerEnum;
import com.hy.mydesktop.client.component.type.ComponentTypeEnum;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentControllerMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.GxtComponentMetaNodeModel;
import com.hy.mydesktop.shared.persistence.domain.gxt.constant.MetaDataConstants;

public class FormPanelBuilderTemplate {

	public static GxtComponentControllerMetaNodeModel createFormPanelBuilderTemplate(
			Map<String, Object> map1, Map<String, Object> map2) {
		Map<String, Object> sumFormPanelController=new HashMap<String, Object>();
		sumFormPanelController.put("component_controller_model_type", ComponentControllerEnum.FORMPANEL_CONTROLLER_MODEL);
		sumFormPanelController.put("component_controller_model_type_index", ComponentControllerEnum.FORMPANEL_CONTROLLER_MODEL.ordinal());
		
		

		GxtComponentControllerMetaNodeModel node45=new GxtComponentControllerMetaNodeModel(sumFormPanelController, 7, 10);
		node45 = ControllerAndComponentMetaNodeModelCreationTemplate.buildCommonAttributes(node45,map1);
		if (map1.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID)!=null) {	
			String controllerMetaModelId=(String)map1.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID);
			String id="formPanelController_"+controllerMetaModelId;
			node45.setId(id);
			node45.setControllerMetaNodeModelId(id);
		}else {
			throw new RuntimeException("xxxxxxxxxxxxx");
		}
		
		map2.put(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID, node45.getControllerMetaNodeModelId());
		GxtComponentMetaNodeModel gxtComponentMetaNodeModel =getSumFormPanelGxtComponentMetaNodeModel(map2);
		node45.setGxtComponentMetaNodeModel(gxtComponentMetaNodeModel);
		
		return node45;

		
	}

	private static GxtComponentMetaNodeModel getSumFormPanelGxtComponentMetaNodeModel(
			Map<String, Object> map2) {
		//创建提交和取消按钮
		Map<String, Object> btnSubmit=new HashMap<String, Object>();
//		btnSubmit.put("component_model_type", ComponentTypeEnum.BUTTON_MODEL);
		//实际创建时，不检查此属性
		btnSubmit.put("component_model_type_index", ComponentTypeEnum.BUTTON_MODEL.ordinal());
		btnSubmit.put("text", "sumFormPanel确定000000");
		btnSubmit.put("id", "03_01_sumFormPanelGxtComponent_PositonType");
		Map<String,Object> codes2 = new HashMap<String, Object>();
		//添加需要监听的事件类型，指定由某一个控制器响应，控制器内部应该如何响应（附加参数和数据）
		/**
		 * 00_01_02为特征码
		 * 或者是 控制器的唯一标识
		 */
		
		btnSubmit.put("registereventtypes", codes2);
		GxtComponentMetaNodeModel btnSubmit1=new GxtComponentMetaNodeModel(btnSubmit);
		
		Map<String, Object> btnquxiao=new HashMap<String, Object>();
//		btnquxiao.put("component_model_type", ComponentTypeEnum.BUTTON_MODEL);
		//实际创建时，不检查此属性
		btnquxiao.put("component_model_type_index", ComponentTypeEnum.BUTTON_MODEL.ordinal());
		btnquxiao.put("text", "取消");
		GxtComponentMetaNodeModel btn1=new GxtComponentMetaNodeModel(btnquxiao);
		
		List<GxtComponentMetaNodeModel> list1=new ArrayList<GxtComponentMetaNodeModel>();
		list1.add(btnSubmit1);
		list1.add(btn1);
		
		
		
		Map<String, Object> formPanelMap=new HashMap<String, Object>();
		formPanelMap.put("component_model_type", ComponentTypeEnum.FORMPANEL_MODEL);
		formPanelMap.put("component_model_type_index", ComponentTypeEnum.FORMPANEL_MODEL.ordinal());
//		formPanelMap.put("width", 800);
//		MaxPanel.put("autoheight", true);
//		MaxPanel.put("height", 600);
		formPanelMap.put("frame", true);
		formPanelMap.put("headervisible", false);
		//TODO MaxPanel.put("addbutton", list1);
		formPanelMap.put("addsubmitbutton", true);
		formPanelMap.put("addresetbutton", true);
		formPanelMap.put("buttonalign", "CENTER");
		formPanelMap.put("layoutindex", ComponentTypeEnum.FORMLAYOUT_MODEL.ordinal());
		//TODO FormPanelHandler.configureFormPanel ( MaxPanel );
		//FormPanelHandler.configureFormPanel ( MaxPanel );
		for (String key : map2.keySet()) {
			formPanelMap.put(key, map2.get(key));
		}
		GxtComponentMetaNodeModel node5=new GxtComponentMetaNodeModel(formPanelMap);
		if (map2.get(MetaDataConstants.FORM_ID)!=null) {
			node5.setId(map2.get(MetaDataConstants.FORM_ID).toString());
		} else {

			if (map2.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID)!=null) {	
				String controllerMetaModelId=(String)map2.get(MetaDataConstants.COMPONENT_CONTROLLER_METAMODEL_ID);
				String id="formPanelGxtComponent_"+controllerMetaModelId;
				node5.setId(id);
			}else {
				throw new RuntimeException("xxxxxxxxxxxxx");
			}
		}
		
		
		node5 =ControllerAndComponentMetaNodeModelCreationTemplate.removeUnusedProperties(node5);

		return node5;
	}

}
